<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
                'id' => 'brand-form',
                'enableAjaxValidation' => false,
            ));
    ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <table>
        <tr>
            <td><?php echo $form->labelEx($model, 'brand_name'); ?> : </td>
            <td>
                <?php echo $form->textField($model, 'brand_name', array('size' => 60, 'maxlength' => 100)); ?>
                <?php echo $form->error($model, 'brand_name'); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo 'Brand Image'; ?> * : </td>
            <td> 
                <input type="hidden" id="brand_image_path" value="<?php echo $model->brand_image_path; ?>" name="Brand[brand_image_path]">
                <?php
                if ($model->brand_image_path) {
                ?>
                    <img onclick="image_upload('brand_image_path', 'preview_brand_image_path');" class="image" id="preview_brand_image_path" alt="" src="<?php echo Yii::app()->request->baseUrl; ?><?php echo $model->brand_image_path; ?> "/>
                <?php
                } else {
                ?>
                    <img onclick="image_upload('brand_image_path', 'preview_brand_image_path');" class="image" id="preview_brand_image_path" alt="" src="<?php echo Yii::app()->request->baseUrl; ?>/images/filemanager/no_image-100x100.jpg"/>
                <?php
                }
                ?>
            </td>
        </tr>
    </table>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/javascript/jquery/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/javascript/jquery/ui/jquery-ui-1.8.9.custom.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/javascript/jquery/ui/themes/ui-lightness/jquery-ui-1.8.9.custom.css" />
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/javascript/jquery/ui/external/jquery.bgiframe-2.1.2.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/javascript/jquery/jstree/jquery.tree.min.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/javascript/jquery/ajaxupload.js"></script>

    <script type="text/javascript"><!--
        function image_upload(field, preview) {
            $('#dialog').remove();
            $('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="<?php echo Yii::app()->request->baseUrl; ?>/index.php/Filemanager/index/field/' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
            $('#dialog').dialog({
                title: 'Image Manager',
                close: function (event, ui) {
                    if ($('#' + field).attr('value')) {
                        $.ajax({
                            url: '<?php echo Yii::app()->request->baseUrl; ?>/index.php/Filemanager/image',
                            type: 'POST',
                            data: 'image=' + encodeURIComponent($('#' + field).attr('value')),
                            dataType: 'text',
                            success: function(data) {
                                $('#' + preview).replaceWith('<img src="' + data + '" alt="" id="' + preview + '" class="image" onclick="image_upload(\'' + field + '\', \'' + preview + '\');" />');
                            }
                        });
                    }
                },
                bgiframe: false,
                width: 800,
                height: 400,
                resizable: false,
                modal: false
            });
        };
        //--></script>


    <div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

<?php $this->endWidget(); ?>

</div><!-- form -->